package org.example.domain;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * 统一响应类
 * @Author hxy
 * @Date 2021/3/15 10:33
 * @Version 1.0
 */
@ApiModel(value = "响应结果")
public class Result<T> implements Serializable {
    @ApiModelProperty(value = "状态码")
    private int code;

    @ApiModelProperty(value = "响应信息")
    private String msg;

    @ApiModelProperty(value = "数据")
    private T data;


    public Result() {

    }

    public static <T> Result<T> success(T data) {
        Result result = new Result<>();
        result.code = 200;
        result.data = data;
        result.msg = "操作成功";
        return result;

    }

    public static <T> Result<T> getCode(T data) {
        Result result = new Result<>();
        result.code = 200;
        result.data = data;
        result.msg = "请在2分钟内完成操作";
        return result;

    }

    public static  <T> Result<T> noToken(String msg) {
        Result result = new Result<>();
        result.code = -4;
        result.msg = msg;
        return result;
    }

    public static  <T> Result<T> fail(T data) {
        Result result = new Result<>();
        result.code = -1;
        result.data = data;
        result.msg = "操作失败";
        return result;
    }

    public static  <T> Result<T> fail(String msg) {
        Result result = new Result<>();
        result.code = -1;
        result.msg = msg;
        return result;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
